package com.yootk.webflux.router;

import com.yootk.webflux.handler.MessageHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;

/**
 * 消息路由处理
 */
@Configuration
public class MessageRouter {

    // 进行路由的功能注册
    @Bean
    public RouterFunction<ServerResponse> routeEcho(MessageHandler messageHandler) {
        return RouterFunctions.route(
                RequestPredicates.GET("/echo")              // 匹配最终的处理路由地址
                .and(RequestPredicates.accept(MediaType.TEXT_PLAIN)),   // 设置了匹配的请求类型
                messageHandler::echoHandler);   // 设置处理方法
    }
}
